<?
	include("includes/config.php");
	include("includes/login.php");
	include("includes/functions.php");
	$id_utilizator = $_SESSION['id_utilizator'];
	if(@$_POST['modifica']){
		$id_unitate = $_POST['id_unitate'];
		$id_pret = $_POST['id_pret'];
		$manopera = $_POST['manopera'];
		$pret = $_POST['pret'];
		
		mysql_query("update preturi set 
			tip_manopera = '$manopera', 
			pret = '$pret'
			where id_unitate = '$id_unitate' and id = '$id_pret'
		")or die(mysql_error());
	}
	if(@$_POST['sterge']){
		$id_pret = $_POST['id_pret'];
		mysql_query("delete from preturi where id='$id_pret'");
	}
	if(@$_POST['add']){
			$id_unitate = $_POST['id_unitate'];
			$manopera = $_POST['manopera'];
			$pret = $_POST['pret'];
			mysql_query("insert into preturi (id,id_unitate,tip_manopera,pret) values(NULL,'$id_unitate','$manopera','$pret') ");
	}
?>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	<body>
		<div id="header"><h1> <? echo detaliFirma('nume_firma'); ?></h1></div>
		<div id="warper">
			<?
				$resMeniu = mysql_query("select * from meniu");
			?>
			<div id="menu">
				<ul>
					<? while($rowMen = mysql_fetch_array($resMeniu)): ?>
					<li><a href="<?echo $rowMen['link'];?>"><? echo $rowMen['numeLink']; ?></a></li>
					<? endwhile; ?>
				</ul>
			</div>
			<div id="content">
				<div id="contentWrap">
					<div class="block">
						<a  class="buton" href="/settings.php">Setari Unitate</a>&nbsp; 
						<a class="buton" href="punctlucru.php">Setari puncte lucru</a>
						<a class="buton" href="/preturi.php">Setari preturi</a>
					</div>
					<div class="block">
						<h1>Preturi </h1>
						<?
							$res = mysql_query("select * from preturi where id_unitate = '$id_utilizator' ");
						?>
				
						<table >
							<tr id="capTabel">
								<td>Tip Manopera</td>
								<td>Pret</td>
								<td>Modifica</td>
							</tr>
							<? while($row = mysql_fetch_array($res)): ?>
							<tr>
								<form action=" " method="post">
								<input type="hidden" name="id_unitate" value="<? echo $row['id_unitate'];?>">
								<input type="hidden" name="id_pret" value="<? echo $row['id'];?>">
								<td align="center"><input  style="width:200px;" type="text" class="text" name="manopera" value="<? echo $row['tip_manopera']; ?>"></td>
								<td align="center"><input style="width:80px;" type="text" class="text" name="pret" value="<? echo $row['pret']; ?>"></td>
								<td>
									<input type="submit" class="buton" name="modifica" value="Modifica">
								</form>
								<form action="" method="post" style="float:right;padding:0;margin:0">
											<input type="hidden" name="id_pret" value="<? echo $row['id'];?>">
											<input type="submit" class="buton" name="sterge" value="Sterge">	
								</form>
								</td>
							</tr>
							<? endwhile; ?>
							
						</table>
					</div>
					
					<h2>Adauga manopera si pret</h2>
					<form action="" method="post">
						<p>
							<label>Manopera</label>
							<input   type="text" class="text" name="manopera" value="">
						</p>
						<p>
							<label>Pret</label>
							<input   type="text" class="text" name="pret" value="">
						</p>
						<input type="hidden" value="<? echo $id_utilizator; ?>" name="id_unitate"/>
						<input type="submit" class="buton" name="add" value="Adauga">	
					</form>
				</div>
			
			</div>
		</div>
	</body>
</html>
